package com.mall.utils;

import org.apache.commons.mail.HtmlEmail;

/**
 * java邮件发送 qq邮箱发送
 */
public class EmailUtil {
    private static  final String USERNAME="huang.shaopeng@qq.com";
    private static  final String PASSWORD="viaeawgwcmzfbidf";
    public  static boolean sendEmail(String []emails,String msg,
                                     String title){

        try {

            HtmlEmail email=new HtmlEmail();
            //基本设置
            email.setSSL(true);
            email.setDebug(true);
            //设置主邮箱为qq邮箱
            email.setHostName("SMTP.qq.com");
            email.setSmtpPort(587);

            //设置发送的邮箱 PASSWORD不是QQ，QQ邮箱密码
            email.setAuthentication(USERNAME,PASSWORD);
            email.setFrom(USERNAME);


               email.addTo(emails);
               email.setMsg(msg);
               email.setSubject(title);
               //执行发送
               email.send();
               return true;


        }catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }

    public static void main(String[] args) {
        String emails[]={"842371845@qq.com"};
        String msg="测试邮寄";
        String title="密码找回";
        boolean b=sendEmail(emails,msg,title);
        System.out.println("邮件发送"+(b?"成功":"失败"));
    }
}
